package com.leetcode.partition8;

/**
 * @author `RKC`
 * @date 2021/9/16 12:15
 */
public class LC740删除并获得点数 {

    public static int deleteAndEarn(int[] nums) {
        return dynamicProgramming(nums);
    }

    public static void main(String[] args) {
        int[] nums = {2, 2, 3, 3, 3, 4};
        System.out.println(dynamicProgramming(nums));
    }

    private static int dynamicProgramming(int[] nums) {
        int[] numsArray = new int[10001];
        //将原数组转换成每个点数对应的大小，问题就成了打家劫舍问题了
        for (int i = 0; i < nums.length; i++) numsArray[nums[i]] += nums[i];
        int[] dp = new int[10001];
        dp[0] = 0;
        dp[1] = numsArray[1];
        for (int i = 2; i < numsArray.length; i++) {
            dp[i] = Math.max(dp[i - 1], dp[i - 2] + numsArray[i]);
        }
        return dp[dp.length - 1];
    }
}
